const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const { version, name, distName, description } = require("../package.json");
const path = require("path");

function resolve(dir) {
  return path.join(__dirname, '..', dir)
}

module.exports = {
  entry: {
    [distName]: [resolve("src/components/index.js")]
  },
  output: {
    library: distName,
    libraryTarget: "umd",
    umdNamedDefine: true, // 是否将模块名称作为 AMD 输出的命名空间
    path: path.join(process.cwd(), "build"),
    filename: "dist/[name].min.js",
    auxiliaryComment: {
      root: 'Root Comment',
      commonjs: 'CommonJS Comment',
      commonjs2: 'CommonJS2 Comment',
      amd: 'AMD Comment'
    }
  },
  externals: {
    react: {
      root: "React",
      commonjs2: "react",
      commonjs: "react",
      amd: "react"
    },
    "react-dom": {
      root: "ReactDOM",
      commonjs2: "react-dom",
      commonjs: "react-dom",
      amd: "react-dom"
    }
  },
  optimization: {
    // minimize: false,//取消内置压缩
  },
  mode: 'production',
  devtool: 'none',
  resolve: {
    enforceExtension: false,
    extensions: ['mjs', ".js", ".jsx", ".json", ".less", ".css"]
  },
  plugins: [
    new MiniCssExtractPlugin({
      filename: 'dist/[name].min.css',
      chunkFilename: 'dist/[name].min.css',
    }),
  ],
}
